home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Include / FWFont.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  8.0 KB  |  302 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFont.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWFONT_H
  11. #define FWFONT_H
  12.  
  13. #ifndef FWGRDEF_H
  14. #include "FWGrDef.h"
  15. #endif
  16.  
  17. #ifndef FWGROBJ_H
  18. #include "FWGrObj.h"
  19. #endif
  20.  
  21. #ifndef FWGRGLOB_H
  22. #include "FWGrGlob.h"
  23. #endif
  24.  
  25. #ifndef FWGCONST_H
  26. #include "FWGConst.h"
  27. #endif
  28.  
  29. #ifndef FWCOLOR_H
  30. #include "FWColor.h"
  31. #endif
  32.  
  33. #ifndef FWGC_H
  34. #include "FWGC.h"
  35. #endif
  36.  
  37. // ----- Foundation Includes -----
  38.  
  39. #ifndef FWSTRING_H
  40. #include "FWString.h"
  41. #endif
  42.  
  43. #if FW_LIB_EXPORT_PRAGMAS
  44. #pragma lib_export on
  45. #endif
  46.  
  47. //========================================================================================
  48. //    Forward Class Declarations
  49. //========================================================================================
  50.  
  51. class FW_CLASS_ATTR FW_CFontRep;
  52. class FW_CLASS_ATTR FW_CGraphicDevice;
  53.  
  54. //========================================================================================
  55. //    struct FW_SFontMetrics
  56. //========================================================================================
  57. //    For an explanation of why I divide everything by 20 on Windows, look at 
  58. //    FW_SFontMetrics::PrivGetFontMetrics
  59.  
  60. #ifdef FW_BUILD_MAC
  61. struct FW_SFontMetrics : public FontInfo
  62. #endif
  63. #ifdef FW_BUILD_WIN
  64. struct FW_CLASS_ATTR FW_SFontMetrics : public TEXTMETRIC
  65. #endif
  66. {
  67.     FW_SFontMetrics() {};
  68.     
  69.     short    GetAscent() const;
  70.     short    GetDescent() const;
  71.     short    GetInternalLeading() const;
  72.     short    GetExternalLeading() const;
  73.     short    GetFontHeight() const;
  74.     short    GetLineSpacing() const;
  75.     
  76.     static void    PrivGetFontMetrics(FW_CGraphicDevice* device, FW_SFontMetrics& fontMetrics);
  77. };
  78.  
  79. //----------------------------------------------------------------------------------------
  80. //    FW_SFontMetrics::GetLineSpacing
  81. //----------------------------------------------------------------------------------------
  82. inline short FW_SFontMetrics::GetLineSpacing() const
  83. {
  84. #ifdef FW_BUILD_MAC
  85.     return ascent + descent + leading;
  86. #endif
  87. #ifdef FW_BUILD_WIN
  88.     return tmHeight / 20;
  89. #endif
  90. }
  91.  
  92. //----------------------------------------------------------------------------------------
  93. //    FW_SFontMetrics::GetAscent
  94. //----------------------------------------------------------------------------------------
  95. inline short FW_SFontMetrics::GetAscent() const
  96. {
  97. #ifdef FW_BUILD_MAC
  98.     return ascent;
  99. #endif
  100. #ifdef FW_BUILD_WIN
  101.     return tmAscent / 20;
  102. #endif
  103. }
  104.  
  105. //----------------------------------------------------------------------------------------
  106. //    FW_SFontMetrics::GetDescent
  107. //----------------------------------------------------------------------------------------
  108. inline short FW_SFontMetrics::GetDescent() const
  109. {
  110. #ifdef FW_BUILD_MAC
  111.     return descent;
  112. #endif
  113. #ifdef FW_BUILD_WIN
  114.     return tmDescent / 20;
  115. #endif
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. //    FW_SFontMetrics::GetExternalLeading
  120. //----------------------------------------------------------------------------------------
  121. inline short FW_SFontMetrics::GetExternalLeading() const
  122. {
  123. #ifdef FW_BUILD_MAC
  124.     return 0;
  125. #endif
  126. #ifdef FW_BUILD_WIN
  127.     return tmExternalLeading / 20;
  128. #endif
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_SFontMetrics::GetInternalLeading
  133. //----------------------------------------------------------------------------------------
  134. inline short FW_SFontMetrics::GetInternalLeading() const
  135. {
  136. #ifdef FW_BUILD_MAC
  137.     return leading;
  138. #endif
  139. #ifdef FW_BUILD_WIN
  140.     return tmInternalLeading / 20;
  141. #endif
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. //    FW_SFontMetrics::GetFontHeight
  146. //----------------------------------------------------------------------------------------
  147. inline short FW_SFontMetrics::GetFontHeight() const
  148. {
  149. #ifdef FW_BUILD_MAC
  150.     return ascent + descent;
  151. #endif
  152. #ifdef FW_BUILD_WIN
  153.     return (tmHeight - tmInternalLeading) / 20;
  154. #endif
  155. }
  156.  
  157. //========================================================================================
  158. //    CLASS FW_PFont
  159. //========================================================================================
  160.  
  161. class FW_CLASS_ATTR FW_PFont : public FW_CGraphicCountedPtr
  162. {
  163. public:
  164.     FW_DECLARE_CLASS
  165.  
  166. public:
  167.     FW_PFont();
  168.     virtual ~ FW_PFont();
  169.     
  170.     
  171.     FW_PFont(const FW_CString& fontName, FW_FontStyle fontStyle, FW_CFixed fontSize);
  172.     
  173.     FW_PFont(const FW_PFont& other);
  174.     FW_PFont& operator=(const FW_PFont& other);
  175.  
  176.     FW_PFont(FW_CFontRep* fontRep);
  177.     FW_PFont& operator=(FW_CFontRep* fontRep);
  178.     
  179.     FW_PFont(FW_EStandardFonts std);
  180.     FW_PFont& operator=(FW_EStandardFonts std);
  181.  
  182.     FW_CFontRep* operator->();
  183.     const FW_CFontRep* operator->() const;
  184. };
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    FW_PFont::operator->
  188. //----------------------------------------------------------------------------------------
  189. inline FW_CFontRep* FW_PFont::operator->()
  190. {
  191.     return (FW_CFontRep*)GetRep();
  192. }
  193.  
  194. //----------------------------------------------------------------------------------------
  195. //    FW_PFont::operator->
  196. //----------------------------------------------------------------------------------------
  197. inline const FW_CFontRep* FW_PFont::operator->() const
  198. {
  199.     return (const FW_CFontRep*)GetRep();
  200. }
  201.  
  202. //========================================================================================
  203. //    class FW_CFontRep
  204. //========================================================================================
  205.  
  206. class FW_CLASS_ATTR FW_CFontRep : public FW_CGraphicCountedPtrRep
  207. {
  208.     friend class FW_CLASS_ATTR FW_PFont;
  209.  
  210. public:
  211.     FW_DECLARE_CLASS
  212.  
  213. //----------------------------------------------------------------------------------------
  214. //    Constructors/Destructors
  215. //
  216. public:
  217.     FW_CFontRep();    
  218.     FW_CFontRep(const FW_CString& fontName, FW_FontStyle fontStyle, FW_CFixed fontSize);
  219.     FW_CFontRep(const FW_CFontRep& otherRep);
  220.     FW_CFontRep(FW_CReadableStream& archive);
  221.  
  222.     FW_CFontRep& operator=(const FW_CFontRep& otherRep);
  223.     
  224.     virtual ~FW_CFontRep();
  225.  
  226. //----------------------------------------------------------------------------------------
  227. //    Memory management
  228. //
  229. public:
  230.     void*                operator new(size_t size);
  231.     void                operator delete(void* p);
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    Inherited API
  235. //
  236. public:
  237.     virtual void    Flatten(FW_CWritableStream& archive) const;
  238.     
  239.     virtual FW_Boolean IsEqual(const FW_CGraphicCountedPtrRep* other) const;
  240.     
  241. //----------------------------------------------------------------------------------------
  242. //    New API
  243. //
  244. public:
  245.     // ----- Copying -----
  246.     FW_PFont            Copy() const;
  247.     
  248.     // ----- Archiving -----
  249.     static void*        Read(FW_CReadableStream& archive);
  250.     
  251.     // ----- Accessors -----
  252.     void                SetFontSize(FW_CFixed fontSize)
  253.                             {fFontSize = fontSize;}
  254.     FW_CFixed            GetFontSize() const
  255.                             {return fFontSize;}
  256.  
  257.     void                SetFontStyle(FW_FontStyle fontStyle);
  258.     FW_FontStyle         GetFontStyle() const
  259.                             {return fFontStyle;}
  260.  
  261.     void                SetFontName(const FW_CString& fontName);
  262.     void                GetFontName(FW_CString& fontName) const
  263.                             {fontName = fFontName;}
  264.  
  265.     void                GetFontMetrics(FW_CGraphicDevice* device, FW_SFontMetrics& fontMetrics) const;
  266.     void                GetFontMetrics(FW_CGraphicContext& gc, FW_SFontMetrics& fontMetrics) const
  267.                             {GetFontMetrics(gc.GetGraphicDevice(), fontMetrics);}
  268.     
  269. //----------------------------------------------------------------------------------------
  270. //    Internal use Only
  271. //
  272. public:    
  273. #ifdef FW_BUILD_MAC
  274.     short                MacGetFontID() const;
  275.     Style                MacGetFontStyle() const;
  276.  
  277. protected:
  278.     void                MacCheckFontCache();
  279. #endif
  280.                             
  281. //----------------------------------------------------------------------------------------
  282. //    Data Members
  283. //
  284. private:
  285.     FW_CDynamicString    fFontName;
  286.     FW_FontStyle        fFontStyle;
  287.     FW_CFixed            fFontSize;        // Font size always in point (1/72")
  288.  
  289. #ifdef FW_BUILD_MAC
  290.     FW_Boolean            fMacValidCache;
  291.     short                fMacFontID;
  292.     Style                fMacFontStyle;
  293.     FW_Boolean            fMacFontNotFound;
  294. #endif
  295. };
  296.  
  297. #if FW_LIB_EXPORT_PRAGMAS
  298. #pragma lib_export off
  299. #endif
  300.  
  301. #endif
  302.